﻿namespace GuiaTest
{
    using System;
    using Guia.Core;
    using Guia.Elements;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using WpfTestApplication;

    /// <summary>
    /// Summary description for ToolBarTest
    /// </summary>
    [TestClass]
    public class ToolBarTest : AbstractWindowTest
    {
        private const int TimeoutTime = 200;

        [TestMethod]
        public void TestSelectButton()
        {
            ToolBar toolBar1 = this.window.Get<ToolBar>("toolBar1");
            Label label1 = this.window.Get<Label>("label1");
            toolBar1.Get<Button>("btn1").Invoke();
            Delay.ForMilliseconds(TimeoutTime);
            Assert.AreEqual("Button 1", label1.TextValue);
            toolBar1.Get<Button>("btn5").Invoke();
            Delay.ForMilliseconds(TimeoutTime);
            Assert.AreEqual("Button 5", label1.TextValue);
        }

        [TestMethod]
        public void TestSelectHiddenButton()
        {
            ToolBar toolBar1 = this.window.Get<ToolBar>("toolBar1");
            Label label1 = this.window.Get<Label>("label1");
            toolBar1.GetItem<Button>("btn9").Invoke();
            Delay.ForMilliseconds(TimeoutTime);
            Assert.AreEqual("Button 9", label1.TextValue);
        }

        [TestMethod]
        public void TestExpandCollapse()
        {
            ToolBar toolBar1 = this.window.Get<ToolBar>("toolBar1");
            Assert.IsFalse(toolBar1.IsExpanded);
            toolBar1.Expand();
            Assert.IsTrue(toolBar1.IsExpanded);
            toolBar1.Collapse();
            Assert.IsFalse(toolBar1.IsExpanded);
        }

        [TestMethod]
        public void TestExpandCollapseProperty()
        {
            ToolBar toolBar1 = this.window.Get<ToolBar>("toolBar1");
            Assert.IsFalse(toolBar1.IsExpanded);
            toolBar1.IsExpanded = true;
            Assert.IsTrue(toolBar1.IsExpanded);
            toolBar1.IsExpanded = false;
            Assert.IsFalse(toolBar1.IsExpanded);
        }

        [TestMethod]
        public void TestGetItem()
        {
            ToolBar toolBar1 = this.window.Get<ToolBar>("toolBar1");
            Button button1 = toolBar1.GetItem<Button>("btn1");
            Assert.AreEqual("btn1", button1.AutomationId);
            Assert.AreEqual("Button 1", button1.TextValue);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void TestGetItemWithNullValue()
        {
            ToolBar toolBar1 = this.window.Get<ToolBar>("toolBar1");
            Button button1 = toolBar1.GetItem<Button>(null);
        }

        [TestMethod,ExpectedException(typeof(ElementNotFoundException))]
        public void TestGetItemWithUnavailableItem()
        {
            ToolBar toolBar1 = this.window.Get<ToolBar>("toolBar1");
            toolBar1.GetItem<Button>("btnInexistend");
        }

        [TestMethod, ExpectedException(typeof(ElementNotFoundException))]
        public void TestGetItemWithUnavailableItemExpanded()
        {
            ToolBar toolBar1 = this.window.Get<ToolBar>("toolBar1");
            toolBar1.Expand();
            toolBar1.GetItem<Button>("btnInexistend");
        }

        protected override Type TestWindowType()
        {
            return typeof (ToolBarTestWindow);
        }

        protected override string TestWindowName()
        {
            return "ToolBarTestWindow";
        }
    }
}
